'\" te
.\" Copyright (c) 2001, Sun Microsystems, Inc.  All Rights Reserved.
.\" Copyright 1989 AT&T
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH DELAY 9F "Oct 15, 2001"
.SH NAME
delay \- delay execution for a specified number of clock ticks
.SH SYNOPSIS
.LP
.nf
#include <sys/ddi.h>



\fBvoid\fR \fBdelay\fR(\fBclock_t\fR \fIticks\fR);
.fi

.SH INTERFACE LEVEL
.sp
.LP
Architecture independent level 1 (DDI/DKI).
.SH PARAMETERS
.sp
.ne 2
.na
\fB\fIticks\fR \fR
.ad
.RS 10n
The number of clock cycles to delay.
.RE

.SH DESCRIPTION
.sp
.LP
\fBdelay()\fR provides a mechanism for a driver to delay its execution for a
given period of time. Since the speed of the clock varies among systems,
drivers should base their time values on microseconds and use
\fBdrv_usectohz\fR(9F) to convert microseconds into clock ticks.
.sp
.LP
\fBdelay()\fR uses \fBtimeout\fR(9F) to schedule an internal function to be
called after the specified amount of time has elapsed. \fBdelay()\fR then waits
until the function is called. Because \fBtimeout()\fR is subject to priority
inversion, drivers waiting on behalf of processes with real-time constraints
should use \fBcv_timedwait\fR(9F) rather than \fBdelay()\fR.
.sp
.LP
\fBdelay()\fR does not busy-wait. If busy-waiting is required, use
\fBdrv_usecwait\fR(9F).
.SH CONTEXT
.sp
.LP
\fBdelay()\fR can be called from user and kernel contexts.
.SH EXAMPLES
.LP
\fBExample 1 \fR\fBdelay()\fR Example
.sp
.LP
Before a driver I/O routine allocates buffers and stores any user data in them,
it checks the status of the device (line 12). If the device needs manual
intervention (such as, needing to be refilled with paper), a message is
displayed on the system console (line 14). The driver waits an allotted time
(line 17) before repeating the procedure.

.sp
.in +2
.nf
 1  struct  device  {	/* layout of physical device registers */
 2          int      control;	/* physical device control word */
 3          int      status;	/* physical device status word */
 4          short    xmit_char;	/* transmit character to device */
 5  };
 6
 7
    ...
 9      /* get device registers */
10      register struct device *rp = ...
11
12      while (rp->status & NOPAPER) {  /* while printer is out of paper */
13                                      /* display message and ring bell */
                                        /* on system console */
14          cmn_err(CE_WARN, "^\e007",
15              (getminor(dev) & 0xf));
16          /* wait one minute and try again */
17          delay(60 * drv_usectohz(1000000));
18      }
.fi
.in -2

.SH SEE ALSO
.sp
.LP
.BR biodone (9F),
.BR biowait (9F),
.BR cv_timedwait (9F),
.BR ddi_in_panic (9F),
.BR drv_hztousec (9F),
.BR drv_usectohz (9F),
.BR drv_usecwait (9F),
.BR timeout (9F),
.BR untimeout (9F)
.sp
.LP
\fIWriting Device Drivers\fR
